// 算一算 部分习题数组 1 - 两位数加减
export function getStudySYS1(studyType, num) {
  let ufuncArr = ['+', '-'] // 运算法则
  let studyAll = []
  for (let i = 1; i <= num; i++) {
    let studyItem = []
    // 随机得到 num1
    let num1 = Math.floor(Math.random() * (studyType[1] - studyType[0]) + studyType[0] + 1)
    studyItem[0] = num1
    // 随机得到 运算规则
    let ufunc = ''
    let index = Math.floor(Math.random() * ufuncArr.length)
    ufunc = ufuncArr[index]
    studyItem[1] = ufunc
    // 根据 num1 和运算规则 随机得到 num2
    let num2 = 0
    if (ufunc == '+') {
      let jieguo = studyType[1] - studyItem[0]
      num2 = Math.floor(Math.random() * jieguo + 1)
    } else if (ufunc == '-') {
      num2 = Math.floor(Math.random() * num1 + 1)
    }
    studyItem[2] = num2
    // 得到该试题的结果
    let result = ''
    if (ufunc == '+') result = (num1 + num2)
    if (ufunc == '-') result = (num1 - num2)
    studyItem[3] = result
    // studyItem 添加到所有的试题中
    studyAll.push(studyItem)
  }
  return studyAll
}

// 算一算 部分习题数组 2 - 三位数加减
export function getStudySYS2(studyType, num) {
  let ufuncArr = ['+', '-'] // 运算法则
  let studyAll = []
  for (let i = 1; i <= num; i++) {
    let studyItem = []
    // 随机得到 num1
    let num1 = Math.floor(Math.random() * (studyType[1] - studyType[0]) + studyType[0] + 1)
    studyItem[0] = num1
    // 随机得到 第一个运算规则
    let ufunc1 = ''
    let index1 = Math.floor(Math.random() * ufuncArr.length)
    ufunc1 = ufuncArr[index1]
    studyItem[1] = ufunc1
    // 根据 num1 和运算规则 随机得到 num2
    let num2 = 0
    if (ufunc1 == '+') {
      let jieguo = studyType[1] - studyItem[0]
      num2 = Math.floor(Math.random() * jieguo + 1)
    } else if (ufunc1 == '-') {
      num2 = Math.floor(Math.random() * num1)
    }
    studyItem[2] = num2
    // 计算 num1 ufunc1 num2 的计算结果 -- result12
    let result12 = 0
    if (ufunc1 == '+') result12 = (num1 + num2)
    if (ufunc1 == '-') result12 = (num1 - num2)
    // 随机得到 第一个运算规则
    let ufunc2 = ''
    let index2 = Math.floor(Math.random() * ufuncArr.length)
    ufunc2 = ufuncArr[index2]
    studyItem[3] = ufunc2
    // 根据 num1 num2 和运算规则 随机得到 num3
    let num3 = 0
    if (ufunc2 == '+') {
      let jieguo = studyType[1] - result12
      num3 = Math.floor(Math.random() * jieguo + 1)
    } else if (ufunc2 == '-') {
      num3 = Math.floor(Math.random() * result12)
    }
    studyItem[4] = num3
    // 得到该试题的结果
    let result123 = 0
    if (ufunc2 == '+') result123 = (result12 + num3)
    if (ufunc2 == '-') result123 = (result12 - num3)
    studyItem[5] = result123
    // studyItem 添加到所有的试题中
    studyAll.push(studyItem)
  }
  return studyAll
}

// 填一填 部分习题数组 1 - 格式 -- num1 + num2 = num3
export function getStudyTYT1(studyType, num) {
  let ufuncArr = ['+', '-'] // 运算法则
  let studyAll = []
  for (let i = 1; i <= num; i++) {
    let studyItem = []
    // 随机得到 num1
    let num1 = Math.floor(Math.random() * (studyType[1] - studyType[0]) + studyType[0] + 1)
    studyItem[0] = num1
    // 随机得到 运算规则
    let ufunc = ''
    let index = Math.floor(Math.random() * ufuncArr.length)
    ufunc = ufuncArr[index]
    studyItem[1] = ufunc
    // 根据 num1 和运算规则 随机得到 num2
    let num2 = 0
    if (ufunc == '+') {
      let jieguo = studyType[1] - studyItem[0]
      num2 = Math.floor(Math.random() * jieguo + 1)
    } else if (ufunc == '-') {
      num2 = Math.floor(Math.random() * num1 + 1)
    }
    studyItem[2] = num2
    // 得到该试题的结果
    let result = ''
    if (ufunc == '+') result = (num1 + num2)
    if (ufunc == '-') result = (num1 - num2)
    studyItem[3] = result
    // 随机隐藏 num1 或者 num2 数字
    let noShowArr = ['num1', 'num2']
    let noShow = Math.floor(Math.random() * ufuncArr.length)
    studyItem[4] = noShowArr[noShow]
    // studyItem 添加到所有的试题中
    studyAll.push(studyItem)
  }
  return studyAll
}

// 填一填 部分习题数组 2 - 格式 -- num1 + num2 = num3 + num4
export function getStudyTYT2(studyType, num) {
  let ufuncArr = ['+', '-'] // 运算法则
  let studyAll = []
  for (let i = 1; i <= num; i++) {
    let studyItem = []
    // 随机得到 num1
    let num1 = Math.floor(Math.random() * (studyType[1] - studyType[0]) + studyType[0] + 1)
    studyItem[0] = num1
    // 随机得到 左侧运算规则
    let ufunc1 = ''
    let index1 = Math.floor(Math.random() * ufuncArr.length)
    ufunc1 = ufuncArr[index1]
    studyItem[1] = ufunc1
    // 根据 num1 和左侧运算规则 随机得到 num2
    let num2 = 0
    if (ufunc1 == '+') {
      let jieguo = studyType[1] - studyItem[0]
      num2 = Math.floor(Math.random() * jieguo + 1)
    } else if (ufunc1 == '-') {
      num2 = Math.floor(Math.random() * (num1 - 1) + 1)
    }
    studyItem[2] = num2
    // 得到该试题的结果
    let result = ''
    if (ufunc1 == '+') result = (num1 + num2)
    if (ufunc1 == '-') result = (num1 - num2)
    // 随机得到 右侧运算规则
    let ufunc2 = ''
    let index2 = Math.floor(Math.random() * ufuncArr.length)
    ufunc2 = ufuncArr[index2]
    studyItem[4] = ufunc2
    // 根据 result 和右侧运算规则 随机得到 num3
    let num3 = 0
    if (ufunc2 == '+') {
      num3 = Math.floor(Math.random() * (result - 1) + 1)
    } else if (ufunc2 == '-') {
      let jieguo = studyType[1] - result
      num3 = Math.floor(Math.random() * jieguo + result + 1)
    }
    studyItem[3] = num3
    // 根据 result 和右侧运算规则 和num3 得到 num4
    let num4 = 0
    if (ufunc2 == '+') {
      num4 = result - num3
    } else if (ufunc2 == '-') {
      num4 = num3 - result
    }
    studyItem[5] = num4
    // 随机隐藏 num1、 num2、 num3 或者 num4 数字
    let noShowArr = ['num1', 'num2', 'num3', 'num4']
    let noShow = Math.floor(Math.random() * noShowArr.length)
    studyItem[6] = noShowArr[noShow]
    // studyItem 添加到所有的试题中
    studyAll.push(studyItem)
  }
  return studyAll
}

// 比一比 部分习题数组 1 - 格式 -- num1 + num2 > num3
export function getStudyBYB1(studyType, num) {
  let ufuncArr = ['+', '-'] // 运算法则
  let studyAll = []
  for (let i = 1; i <= num; i++) {
    let studyItem = []
    // 随机得到 num1
    let num1 = Math.floor(Math.random() * (studyType[1] - studyType[0]) + studyType[0] + 1)
    studyItem[0] = num1
    // 随机得到 运算规则
    let ufunc = ''
    let index = Math.floor(Math.random() * ufuncArr.length)
    ufunc = ufuncArr[index]
    studyItem[1] = ufunc
    // 根据 num1 和运算规则 随机得到 num2
    let num2 = 0
    if (ufunc == '+') {
      let jieguo = studyType[1] - studyItem[0]
      num2 = Math.floor(Math.random() * jieguo + 1)
    } else if (ufunc == '-') {
      num2 = Math.floor(Math.random() * num1 + 1)
    }
    studyItem[2] = num2
    // 得到该试题的正确结果
    let result = ''
    if (ufunc == '+') result = (num1 + num2)
    if (ufunc == '-') result = (num1 - num2)
    // 根据正确结果 得到一个 num3 的取值范围
    let num3Arr = [result - 3, result - 1, result - 2, result, result + 1, result + 2, result + 3]
    let num3Result = num3Arr.filter(item => { return item > 0 })
    let num3 = 0
    let num3Index = Math.floor(Math.random() * num3Result.length)
    num3 = num3Result[num3Index]
    studyItem[4] = num3
    // 根据正确结果计算 中间的结果是 > , < , 或者是 =
    let getResult = ''
    if (result == num3) getResult = '='
    if (result > num3) getResult = '>'
    if (result < num3) getResult = '<'
    studyItem[3] = getResult
    // studyItem 添加到所有的试题中
    studyAll.push(studyItem)
  }
  return studyAll
}

// 比一比 部分习题数组 2 - 格式 -- num1 + num2 > num3 + num4
export function getStudyBYB2(studyType, num) {
  let ufuncArr = ['+', '-'] // 运算法则
  let studyAll = []
  for (let i = 1; i <= num; i++) {
    let studyItem = []
    // 随机得到 num1
    let num1 = Math.floor(Math.random() * (studyType[1] - studyType[0]) + studyType[0] + 1)
    studyItem[0] = num1
    // 随机得到 左侧运算规则
    let ufunc1 = ''
    let index1 = Math.floor(Math.random() * ufuncArr.length)
    ufunc1 = ufuncArr[index1]
    studyItem[1] = ufunc1
    // 根据 num1 和左侧运算规则 随机得到 num2
    let num2 = 0
    if (ufunc1 == '+') {
      let jieguo = studyType[1] - studyItem[0]
      num2 = Math.floor(Math.random() * jieguo + 1)
    } else if (ufunc1 == '-') {
      num2 = Math.floor(Math.random() * num1)
    }
    studyItem[2] = num2
    // 得到该试题 左侧运算 的结果
    let result1 = ''
    if (ufunc1 == '+') result1 = (num1 + num2)
    if (ufunc1 == '-') result1 = (num1 - num2)
    // 随机得到 右侧运算规则
    let ufunc2 = ''
    let index2 = Math.floor(Math.random() * ufuncArr.length)
    ufunc2 = ufuncArr[index2]
    studyItem[5] = ufunc2
    // 根据正确结果 得到一个 num3 的取值范围
    let result2Arr = [result1 - 3, result1 - 1, result1 - 2, result1, result1 + 1, result1 + 2, result1 + 3]
    let result2Result = result2Arr.filter(item => { return item > 0 })
    let result2Index = Math.floor(Math.random() * result2Result.length)
    let result2 = result2Result[result2Index]
    // 根据 result2 和右侧运算规则 随机得到 num3
    let num3 = 0
    if (ufunc2 == '+') {
      num3 = Math.floor(Math.random() * (result2 - 1))
    } else if (ufunc2 == '-') {
      let jieguo = studyType[1] - result2
      num3 = Math.floor(Math.random() * jieguo + result2 + 2)
    }
    studyItem[4] = num3
    // 根据 num3 和右侧运算规则 随机得到 num4
    let num4 = 0
    if (ufunc2 == '+') { num4 = result2 - num3 }
    if (ufunc2 == '-') { num4 = num3 - result2 }
    studyItem[6] = num4
    // 根据正确结果计算 中间的结果是 > , < , 或者是 =
    let getResult = ''
    if (result1 == result2) { getResult = '=' }
    if (result1 > result2) { getResult = '>' }
    if (result1 < result2) { getResult = '<' }
    studyItem[3] = getResult
    // studyItem 添加到所有的试题中
    studyAll.push(studyItem)
  }
  return studyAll
}

